const { no, ok } = require('../../utils/utlis');

const albumService = require('../../services/admin/albumService');
module.exports = {
	list: async (req, res, next) => {
		try {
			let { pageNum, pageSize, keywords } = req.body;
			let data = await albumService.list(pageNum, pageSize, keywords);
			res.send(ok(data));
		} catch (error) {
			res.send(no(error.message));
		}
	},
	add: async (req, res, next) => {
		try {
			let { name, directoryName, url, filename, isPwd, password, remark } = req.body;

			await albumService.add(name, directoryName, url, filename, isPwd, password, remark);
			res.send(ok());
		} catch (error) {
			res.send(no(error.message));
		}
	},
	edit: async (req, res, next) => {
		try {
			let { id, name, url, filename, isPwd, password, remark } = req.body;
			if (!id) throw new Error('id不能为空');
			await albumService.edit(id, name, url, filename, isPwd, password, remark);
			res.send(ok());
		} catch (error) {
			res.send(no(error.message));
		}
	},
	detail: async (req, res, next) => {
		try {
			let { id } = req.body;
			let obj = await albumService.detail(id);
			res.send(ok(obj));
		} catch (error) {
			res.send(no(error.message));
		}
	},
	del: async (req, res, next) => {
		try {
			let { id } = req.body;
			await albumService.del(id);
			res.send(ok());
		} catch (error) {
			res.send(no(error.message));
		}
	},
	pic: async (req, res, next) => {
		try {
			let { id } = req.body;
			let list = await albumService.pic(id);
			res.send(ok(list));
		} catch (error) {
			res.send(no(error.message));
		}
	},
	delPic: async (req, res, next) => {
		try {
			let { id } = req.body;
			await albumService.delPic(id);
			res.send(ok());
		} catch (error) {
			res.send(no(error.message));
		}
	}
};
